**----------------------------------------------------------------------------**
**--Local Corruption & Household Business Tax Compliance
**--Duong Le, Eddy Malesky, Anh Pham
**--Journal of Economic Behavior and Organization (July 2020)
**----------------------------------------------------------------------------**
**--Do File: Producing all Tables in the Appendix Section
**----------------------------------------------------------------------------**
clear all 
**specify your main directory that stores all replication files
global main_directory = "insert your working directory here" 

//set data working directory
cd "$main_directory\data" 

//Replace with the folder you want to store all result outputs
global result "$main_directory\result"


**-----------------------------------------------------------------------------------***
**---Table 7: The Effect of Corruption on Tax Compliance Ratio - An Alternative Measure
**-----------------------------------------------------------------------------------***
use "firm_commune_pair.dta", clear

global X_ctrls= "age sex i.educ i.location"
global C_GIS_ctrls = "area_km2 boundary_km lat lon"
global C_geo=" elev river suit_rice suit_tea suit_coffee suit_coconut suit_sugar slope tem precip"
global C_policy_ctrls = "ezone_c izone_c taxreduc"
global econ_formal= "nfirmf ld_endme ld_endm ts_asset_endme ts_asset_endm kqkd_rev_busme kqkd_rev_busm kqkd_prof_bftaxme kqkd_prof_bftaxm"
global C_governance="pciECindex_1 pciLAindex_1 pciTindex_1 pciTCindex_1  pciBindex_1 pciPindex_1 pciBSSidex_1 pciLTindex_1 pciLIindex_1"


label var thue11_r2_99 " alternative tax compliance"
label var thue11_r2_99i " alternative tax compliance impute 0"	
	
foreach var in thue11_r2_99 {
	reghdfe `var' pciICindex_1  $C_governance $X_ctrls $C_policy_ctrls  $C_GIS_ctrls light16_mean $C_geo  $econ_formal if thudn1>100000& thudn1<.& econ_formal==1, absorb(com_pairID ind4) cluster(provinceID_2017 borderID ) 
	outreg2 using "$result/Table7.xls", replace excel keep(pciICindex_1 ) ///
	nocons addtext(Sample, kmA0, borderID FE, Yes, 4digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Light2016, Yes, ///
				   Only no-missing geo controls, Yes, Geo controls, Yes, Only no-missing formal sector activities, Yes, Formal sector activities Controls, Yes) 
				   
				   
	reghdfe `var' pciICindex_1  $C_governance $X_ctrls  $C_policy_ctrls  $C_GIS_ctrls light16_mean $C_geo  $econ_formal if thudn1>100000& thudn1<.& econ_formal==1& taxid==1, absorb(com_pairID ind4) cluster(provinceID_2017 borderID ) 
	outreg2 using "$result/Table7.xls",  excel keep(pciICindex_1 ) ///
	nocons addtext(Sample, kmA0& taxid==1, borderID FE, Yes, 4digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Light2016, Yes, ///
				   Only no-missing geo controls, Yes, Geo controls, Yes, Only no-missing formal sector activities, Yes, Formal sector activities Controls, Yes) 			   	
	}	

foreach var in thue11_r2_99i {
	reghdfe `var' pciICindex_1  $C_governance $X_ctrls $C_policy_ctrls  $C_GIS_ctrls light16_mean $C_geo  $econ_formal if thudn1>100000& thudn1<.& econ_formal==1, absorb(com_pairID ind4) cluster(provinceID_2017 borderID ) 
	outreg2 using "$result/Table7.xls",  excel keep(pciICindex_1 ) ///
	nocons addtext(Sample, kmA0, borderID FE, Yes, 4digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Light2016, Yes, ///
				   Only no-missing geo controls, Yes, Geo controls, Yes, Only no-missing formal sector activities, Yes, Formal sector activities Controls, Yes) 
				   
				   
	reghdfe `var' pciICindex_1  $C_governance $X_ctrls  $C_policy_ctrls  $C_GIS_ctrls light16_mean $C_geo  $econ_formal if thudn1>100000& thudn1<.& econ_formal==1& taxid==1, absorb(com_pairID ind4) cluster(provinceID_2017 borderID ) 
	outreg2 using "$result/Table7.xls",  excel keep(pciICindex_1 ) ///
	nocons addtext(Sample, kmA0& taxid==1, borderID FE, Yes, 4digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Light2016, Yes, ///
				   Only no-missing geo controls, Yes, Geo controls, Yes, Only no-missing formal sector activities, Yes, Formal sector activities Controls, Yes) 
				   	
	}	
	

**----------------------------------------------------------------------------**
**--Table 8: Robustness with provincial-level regressions
**----------------------------------------------------------------------------**
use "VHBS2017.dta", clear 

keep if thudn1>100000 & thudn1<.
drop if tinh==.
drop if provinceID_GIS == .

foreach var in  lnthudn1 worker_total {
	winsor `var', g(`var'_99) p(0.01)
}

winsor thue11_r, g(thue11_r99) p(0.01)

g thue11_r99i=thue11_r99
replace thue11_r99i=0 if thue11_r99==.& phieu!=""

global PCI_sub = "pciECindex pciLAindex pciTindex pciTCindex pciBindex pciPindex pciBSSindex pciLTindex pciLIindex"
global sum_var = "taxid lnthudn1_99 worker_total_99 thue11_r99 thue11_r99i operation_hr rest manu retail wholesale age male notraining house"
gen firmCount = 1
collapse (mean) $sum_var (sum) firmCount (first) provinceID_GIS, by(tinh)

preserve 
use "pci.dta", clear
keep if year==2017

tempfile pci_2017
save `pci_2017'
restore

merge m:1 provinceID_GIS using `pci_2017', keepusing(pciICindex $PCI_sub)
keep if _merge==1|_merge==3 
drop _merge

gen pciICindex_1 = 11-pciICindex
rename thue11_r99 taxComp

foreach var in taxid taxComp  {
	reg `var' pciICindex_1 
	outreg2 using "$result/Table8.xls", keep(pciICindex_1) label excel addtext(PCI_sub covs, No)
	
	reg `var' pciICindex_1 $PCI_sub  
	outreg2 using "$result/Table8.xls", keep(pciICindex_1) label excel addtext(PCI_sub covs, Yes)
}


**----------------------------------------------------------------------------**
**--Table 9: Tobit model as robustness check
**----------------------------------------------------------------------------**
use "VHBS2017.dta", clear
winsor thue11_r, g(taxComp) p(0.01)

g taxComp_imp= taxComp
replace taxComp_imp=0 if taxComp_imp==.& phieu!=""


preserve 
use "pci.dta", clear
keep if year==2017

tempfile pci_2017
save `pci_2017'
restore

global PCI_sub = "pciECindex pciLAindex pciTindex pciTCindex pciBindex pciPindex pciBSSindex pciLTindex pciLIindex"
merge m:1 provinceID_GIS using `pci_2017', keepusing(pciICindex $PCI_sub)
keep if _merge==1|_merge==3 
drop _merge

gen corrupt = 11 - pciICindex

global C_ctrls = "area_km2 boundary_km lat lon"
global X2_ctrls= "age sex"
global geo=" elev river suit_rice suit_tea suit_coffee suit_coconut suit_sugar slope tem precip"
global econ_formal= "nfirmf ld_endme ld_endm ts_asset_endme ts_asset_endm kqkd_rev_busme kqkd_rev_busm kqkd_prof_bftaxme kqkd_prof_bftaxm"
global depV="pciECindex_1 pciLAindex_1 pciTindex_1 pciTCindex_1 pciICindex_1 pciBindex_1 pciPindex_1 pciBSSidex_1 pciLTindex_1 pciLIindex_1"

tostring ind3, gen(ind3_str)
g ind1= "0" if ind3<=99
replace ind1=substr(ind3_str,1,1) if ind3>100
destring ind1, replace

foreach var in taxComp {
	tobit `var' corrupt if taxid==1 & atBorder==1, ll(0) ul(1) 
	outreg2 using "$result/Table9.xls", keep(corrupt) label excel addtext(Model, Tobit, Sample, atBorder OLS, 1-d Industry FE, No)  

	tobit `var' corrupt i.ind1 if taxid==1 & atBorder==1, ll(0) ul(1) 
	outreg2 using "$result/Table9.xls", keep(corrupt) label excel addtext(Model, Tobit, Sample, atBorder OLS, 1-d Industry FE, Yes)  
}

	
**----------------------------------------------------------------------------**
**---Table 10: proximity-pair robustness -- taxID
**----------------------------------------------------------------------------**	
use "firm_commune_pair_proximity_3km.dta", clear

global X_ctrls= "age sex i.educ i.location"
global C_GIS_ctrls = "area_km2 boundary_km lat lon"
global C_geo=" elev river suit_rice suit_tea suit_coffee suit_coconut suit_sugar slope tem precip"
global C_policy_ctrls = "ezone_c izone_c taxreduc"
global econ_formal= "nfirmf ld_endme ld_endm ts_asset_endme ts_asset_endm kqkd_rev_busme kqkd_rev_busm kqkd_prof_bftaxme kqkd_prof_bftaxm"
global C_governance="pciECindex_1 pciLAindex_1 pciTindex_1 pciTCindex_1  pciBindex_1 pciPindex_1 pciBSSindex_1 pciLTindex_1 pciLIindex_1"

**robustness: all sample
foreach var in taxid {	
	foreach km in 1 2 3 {
		reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_policy_ctrls $C_GIS_ctrls $C_geo $econ_formal light16_mean if thudn1>100000 & thudn1<. & km_source_nb<=`km',  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
		outreg2 using "$result/Table10.xls", excel keep(pciICindex_1) ///
		nocons addtext(Sample, `km', comPair FE, Y, 3d-Ind FE, Y, F_ctrls, Y, C_GIS_ctrls, Y, C_geo, Y, Formal_char, Y, Light2016, Y) label 
	}
}


**robustness: further drop HN & HCM
foreach var in taxid {	
	foreach km in 0 1 2 3 {
		reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_policy_ctrls $C_GIS_ctrls $C_geo $econ_formal light16_mean if thudn1>100000 & thudn1<. & km_source_nb<=`km'& tinh!=1 & tinh!=79,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
		outreg2 using "$result/Table10.xls", excel keep(pciICindex_1) ///
		nocons addtext(Sample, `km', comPair FE, Y, 3d-Ind FE, Y, F_ctrls, Y, C_GIS_ctrls, Y, C_geo, Y, Formal_char, Y, Light2016, Y, drop HN&HCM, Y) label 
	}
}

**----------------------------------------------------------------------------**
**---Table 11: proximity-pair robustness -- tax compliance ratio
**----------------------------------------------------------------------------**	

**Panel A
foreach var in taxComp  {	
	foreach km in 1 2 3 {
		reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_policy_ctrls $C_GIS_ctrls $C_geo $econ_formal light16_mean if thudn1>100000 & thudn1<. & econ_formal==1 & km_source_nb<=`km', absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
		outreg2 using "$result/Table11.xls", excel keep(pciICindex_1) ///
		nocons addtext(With taxID, No, Sample,`km' km, comPair FE, Y, 3d-Ind FE, Y, F_ctrls, Y, C_policy_ctrls,Y, C_GIS_ctrls, Y, C_geo, Y, Formal_char, Y, Light2016, Y) label 
	}
	
	*0km; no HCM; HN
	reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_policy_ctrls $C_GIS_ctrls $C_geo $econ_formal light16_mean if thudn1>100000 & thudn1<. & econ_formal==1 & km_source_nb==0 & tinh!=1 & tinh!=79, absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table11.xls", excel keep(pciICindex_1) ///
	nocons addtext(With taxID, No, Sample, 0km & noHCMHN, comPair FE, Y, 3d-Ind FE, Y, F_ctrls, Y, C_policy_ctrls,Y, C_GIS_ctrls, Y, C_geo, Y, Formal_char, Y, Light2016, Y) label 

}

**Panel B
 foreach var in taxComp  {	
	foreach km in 1 2 3 {		
		reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_policy_ctrls $C_GIS_ctrls $C_geo $econ_formal light16_mean if thudn1>100000 & thudn1<. & econ_formal==1 & km_source_nb<=`km' & taxid==1, absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
		outreg2 using "$result/Table11.xls", excel keep(pciICindex_1) ///
		nocons addtext(With taxID, Yes, Sample,`km' km, comPair FE, Y, 3d-Ind FE, Y, F_ctrls, Y, C_GIS_ctrls, Y, C_policy_ctrls,Y, C_geo, Y, Formal_char, Y, Light2016, Y) label 
	}
	
	*0km; no HCM; HN
	reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_policy_ctrls $C_GIS_ctrls $C_geo $econ_formal light16_mean if thudn1>100000 & thudn1<. & econ_formal==1 & km_source_nb==0 & tinh!=1 & tinh!=79 & taxid==1, absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table11.xls", excel keep(pciICindex_1) ///
	nocons addtext(With taxID, Yes, Sample,0km & noHCMHN, comPair FE, Y, 3d-Ind FE, Y, F_ctrls, Y, C_policy_ctrls,Y, C_GIS_ctrls, Y, C_geo, Y, Formal_char, Y, Light2016, Y) label 
}
 
  


**----------------------------------------------------------------------------**
**---Table 12: proximity-pair robustness -- tax compliance ratio imputed
**----------------------------------------------------------------------------**	
**Panel A
foreach var in taxComp_imp  {	
	foreach km in 1 2 3 {
		reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_policy_ctrls $C_GIS_ctrls $C_geo $econ_formal light16_mean if thudn1>100000 & thudn1<. & econ_formal==1 & km_source_nb<=`km', absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
		outreg2 using "$result/Table12.xls", excel keep(pciICindex_1) ///
		nocons addtext(With taxID, No, Sample,`km' km, comPair FE, Y, 3d-Ind FE, Y, F_ctrls, Y, C_policy_ctrls,Y, C_GIS_ctrls, Y, C_geo, Y, Formal_char, Y, Light2016, Y) label 
	}
	
	*0km; no HCM; HN
	reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_policy_ctrls $C_GIS_ctrls $C_geo $econ_formal light16_mean if thudn1>100000 & thudn1<. & econ_formal==1 & km_source_nb==0 & tinh!=1 & tinh!=79, absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table12.xls", excel keep(pciICindex_1) ///
	nocons addtext(With taxID, No, Sample, 0km & noHCMHN, comPair FE, Y, 3d-Ind FE, Y, F_ctrls, Y, C_policy_ctrls,Y, C_GIS_ctrls, Y, C_geo, Y, Formal_char, Y, Light2016, Y) label 

}

**Panel B
 foreach var in taxComp_imp  {	
	foreach km in 1 2 3 {		
		reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_policy_ctrls $C_GIS_ctrls $C_geo $econ_formal light16_mean if thudn1>100000 & thudn1<. & econ_formal==1 & km_source_nb<=`km' & taxid==1, absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
		outreg2 using "$result/Table12.xls", excel keep(pciICindex_1) ///
		nocons addtext(With taxID, Yes, Sample,`km' km, comPair FE, Y, 3d-Ind FE, Y, F_ctrls, Y, C_GIS_ctrls, Y, C_policy_ctrls,Y, C_geo, Y, Formal_char, Y, Light2016, Y) label 
	}
	
	*0km; no HCM; HN
	reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_policy_ctrls $C_GIS_ctrls $C_geo $econ_formal light16_mean if thudn1>100000 & thudn1<. & econ_formal==1 & km_source_nb==0 & tinh!=1 & tinh!=79 & taxid==1, absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table12.xls", excel keep(pciICindex_1) ///
	nocons addtext(With taxID, Yes, Sample,0km & noHCMHN, comPair FE, Y, 3d-Ind FE, Y, F_ctrls, Y, C_policy_ctrls,Y, C_GIS_ctrls, Y, C_geo, Y, Formal_char, Y, Light2016, Y) label 
}
 



**----------------------------------------------------------------------------**
**---Table 13: Revenue Threshold robustness -- possession of tax IDs
**----------------------------------------------------------------------------**
use "firm_commune_pair.dta", clear 
global X_ctrls= "age sex i.educ i.location"
global C_ctrls = "ezone_c izone_c taxreduc area_km2 boundary_km lat lon"
global C_geo=" elev river suit_rice suit_tea suit_coffee suit_coconut suit_sugar slope tem precip"
global econ_formal= "nfirmf ld_endme ld_endm ts_asset_endme ts_asset_endm kqkd_rev_busme kqkd_rev_busm kqkd_prof_bftaxme kqkd_prof_bftaxm"
global C_governance="pciECindex_1 pciLAindex_1 pciTindex_1 pciTCindex_1  pciBindex_1 pciPindex_1 pciBSSindex_1 pciLTindex_1 pciLIindex_1"

foreach var in taxid {	
	foreach revMax in 90000 70000 50000 {
	display `revMax'
		
	reghdfe `var' pciICindex_1 if thudn1>`revMax'& thudn1<. , absorb(com_pairID ind3) cluster(provinceID_2017 borderID) 
	outreg2 using "$result/Table13.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, comPair FE, Y, 3d-Ind FE, Y, Rev Threshold, `revMax') label 
	
	reghdfe `var' pciICindex_1  $X_ctrls if thudn1>`revMax'& thudn1<. , absorb(com_pairID ind3) cluster(provinceID_2017 borderID) 
	outreg2 using "$result/Table13.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, comPair FE, Y, 3d-Ind FE, Y, Rev Threshold, `revMax', F_ctrls, Y) label 
	
	reghdfe `var' pciICindex_1  $X_ctrls $C_ctrls $C_geo light16_mean if thudn1>`revMax'& thudn1<. , absorb(com_pairID ind3) cluster(provinceID_2017 borderID) 
	outreg2 using "$result/Table13.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, comPair FE, Y, 3d-Ind FE, Y, Rev Threshold, `revMax', F_ctrls, Y, C_ctrls, Y,  C_geo, Y, Light2016, Y) label 
	
	reghdfe `var' pciICindex_1  $X_ctrls $C_ctrls $C_geo light16_mean $econ_formal if thudn1>`revMax'& thudn1<.  & econ_formal==1, absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table13.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, comPair FE, Y, 3d-Ind FE, Y, Rev Threshold, `revMax', F_ctrls, Y, C_ctrls, Y, C_geo, Y, Light2016, Y, formal sector Ctrl, Y) label 


	reghdfe `var' pciICindex_1  $X_ctrls $C_ctrls $C_geo light16_mean $econ_formal $C_governance if thudn1>`revMax'& thudn1<.  & econ_formal==1, absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table13.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, comPair FE, Y, 3d-Ind FE, Y, Rev Threshold, `revMax', F_ctrls, Y, C_ctrls, Y, C_geo, Y, Light2016, Y, formal sector Ctrl, Y, governance Ctrl, Y) label 
	}
}


**----------------------------------------------------------------------------**
**---Table 14: Revenue Threshold robustness -- tax compliance ratio
**----------------------------------------------------------------------------**
foreach var in taxComp  {	
	foreach revMax in 50000 70000 90000 {
	display `revMax'
	
	reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_ctrls $C_geo $econ_formal light16_mean if thudn1>`revMax' & thudn1<. & econ_formal==1,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table14.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder-All, comPair FE, Y, 3d-Ind FE, Y, F_ctrls, Y, C_GIS_ctrls, Y, C_geo, Y, Formal_char, Y, Light2016, Y, Rev Threshold, `revMax') label 
	
	reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_ctrls $C_geo $econ_formal light16_mean if thudn1>`revMax' & thudn1<. & econ_formal==1 & taxid==1,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table14.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder-have taxID, comPair FE, Y, 3d-Ind FE, Y, F_ctrls, Y, C_GIS_ctrls, Y, C_geo, Y, Formal_char, Y, Light2016, Y, Rev Threshold, `revMax') label 
	}
}
 
 
 foreach var in taxComp  {	
	foreach revMax in 50000  {
	display `revMax'
	
	reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_ctrls $C_geo $econ_formal light16_mean if thudn1>`revMax' & thudn1<. & econ_formal==1,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	}
 }
	
 
**----------------------------------------------------------------------------**
**---Table 15: Pairwise regressions -- tax payment
**----------------------------------------------------------------------------**
global X_ctrls= "age sex i.educ i.location"
global C_GIS_ctrls = "area_km2 boundary_km lat lon"
global C_geo=" elev river suit_rice suit_tea suit_coffee suit_coconut suit_sugar slope tem precip"
global C_policy_ctrls = "ezone_c izone_c taxreduc"
global econ_formal= "nfirmf ld_endme ld_endm ts_asset_endme ts_asset_endm kqkd_rev_busme kqkd_rev_busm kqkd_prof_bftaxme kqkd_prof_bftaxm"
global C_governance="pciECindex_1 pciLAindex_1 pciTindex_1 pciTCindex_1  pciBindex_1 pciPindex_1 pciBSSindex_1 pciLTindex_1 pciLIindex_1"

foreach var in thue11_99 thue11_99i {	
	reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_policy_ctrls $C_GIS_ctrls light16_mean $C_geo  $econ_formal  if thudn1>100000& thudn1<. ,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table15.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Night-light Index 2016, Yes, Geographical controls, Yes, Formal sector activities controls, Yes) label
	
	reghdfe `var' pciICindex_1 $C_governance $X_ctrls $C_policy_ctrls $C_GIS_ctrls light16_mean $C_geo  $econ_formal if thudn1>100000& thudn1<. & taxid==1,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table15.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder& taxid==1, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Night-light Index 2016, Yes, Geographical controls, Yes, Formal sector activities controls, Yes) label
	}
	
	
**----------------------------------------------------------------------------**
**---Table 16: robustness corruption 2015 & 2016
**----------------------------------------------------------------------------**
*--pci2015
preserve 
use "pci.dta", clear
keep if year==2015

tempfile pci_2015
save `pci_2015'
restore

gen ProvinceID_VES = provinceID_2017
merge m:1 ProvinceID_VES using `pci_2015', keepusing(pciICindex)
keep if _merge==1|_merge==3 
drop _merge

gen pciICindex_2015 = 11-pciICindex
label var taxComp "Tax Compliance Ratio"
label var pciICindex_2015 "corruption 2015"

foreach var in taxid {	
	reghdfe `var' pciICindex_2015 if thudn1>100000& thudn1<.& econ_formal==1 ,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table16.xls", excel keep(pciICindex_2015) nocons addtext(Sample, kmA0, borderID FE, Yes, 3digit Industry FE, Yes) replace label
	}
	
	foreach var in taxComp {	
	reghdfe `var' pciICindex_2015 if thudn1>100000& thudn1<.& econ_formal==1& taxid==1 ,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table16.xls", excel keep(pciICindex_2015) nocons addtext(Sample, kmA0, borderID FE, Yes, 3digit Industry FE, Yes)  label
	}



*--pci2016
drop  pciICindex
preserve 
use "pci.dta", clear
keep if year==2016

tempfile pci_2016
save `pci_2016'
restore

merge m:1 ProvinceID_VES using `pci_2016', keepusing(pciICindex)
keep if _merge==1|_merge==3 
drop _merge
gen pciICindex_2016 = 11-pciICindex
label var pciICindex_2016 "corruption 2016"

foreach var in taxid {	
	reghdfe `var' pciICindex_2016 if thudn1>100000& thudn1<.& econ_formal==1 ,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table16.xls", excel keep(pciICindex_2016) nocons addtext(Sample, kmA0, borderID FE, Yes, 3digit Industry FE, Yes) label	
	}
	
	foreach var in taxComp {	
	reghdfe `var' pciICindex_2016 if thudn1>100000& thudn1<.& econ_formal==1& taxid==1 ,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table16.xls", excel keep(pciICindex_2016) nocons addtext(Sample, kmA0, borderID FE, Yes, 3digit Industry FE, Yes)  label
	}

**----------------------------------------------------------------------------**
**---Table 17: smoothness at provincial border
**----------------------------------------------------------------------------**
use "commune_data_robust.dta", replace
global C_ctrls = "lat lon kmC borderLength_km"

foreach var in area_km2  elev slope precip tem light16_mean  {
	reg `var' higherScore $C_ctrls if atBorder==1, cluster(tinh)
	outreg2 using "$result/Table17.xls", keep(higherScore) excel nocons addtext(Commune Controls,Yes, Bandwidth, atBorder) 
}

**----------------------------------------------------------------------------**
**---Table 18: smoothness at provincial border (cont.)
**----------------------------------------------------------------------------**
foreach var in suit_tea suit_rice suit_coconut suit_coffee suit_sugar {
	reg `var' higherScore $C_ctrls if atBorder==1, cluster(tinh)
	outreg2 using "$result/Table18.xls", keep(higherScore) excel nocons addtext(Commune Controls,Yes, Bandwidth, atBorder) 
}

**----------------------------------------------------------------------------**
**---Table 19: density bunching test
**----------------------------------------------------------------------------**
global C_GIS_ctrls = "area_km2 boundary_km lat lon"
global C_geo=" elev slope tem precip river suit_rice suit_tea suit_coffee suit_coconut suit_sugar"
global econ_formal= "nfirmf ld_endme ld_endm ts_asset_endme ts_asset_endm kqkd_rev_busme kqkd_rev_busm kqkd_prof_bftaxme kqkd_prof_bftaxm"

reghdfe firmCount_ln atBorder $C_GIS_ctrls $C_geo $econ_formal if higherScore==1 & (atBorder==1|neighbor1==1), absorb(borderID) cluster(tinh borderID)
outreg2 using "$result/Table19.xls", keep(atBorder) excel addtext(Commune Controls,Yes, Border FE,Yes, Cluster, 2-way, Bandwidth, neighbor) 

foreach bw in 5 10 20 30 {
	reghdfe firmCount_ln atBorder $C_GIS_ctrls $C_geo $econ_formal if higherScore==1 & kmC<=`bw', absorb(borderID) cluster(tinh borderID)
	outreg2 using "$result/Table19.xls", keep(atBorder) excel addtext(Commune Controls,Yes, Border FE,Yes, Cluster, 2-way, Bandwidth,`bw' kmC) 
	}


**----------------------------------------------------------------------------**
**---Table 20: Corruption, inclusion in the tax-survey, and nonresponse rate
**----------------------------------------------------------------------------**
use "firm_commune_pair.dta", clear 
label var pciICindex_1 "corruption"

**in the tax-survey sample
preserve
duplicates drop id_nganh, force

g phieus=1 if phieu!=""
replace phieus=0 if phieu==""
label var phieus "in the tax-survey sample"

reg phieus pciICindex_1, cluster(provinceID_2017)
outreg2 using "$result/Table20.xls", label excel replace nocons addtext(Sample, at the border) addnote("Standard error cluster at the province level")
restore
	
	
**nonresponse rate when in the tax-survey sample 
preserve
duplicates drop id_nganh, force
keep if phieu!=""

g missing=1 if thue11_r99==.
replace missing=0 if thue11_r99<.
label var missing "nonresponse"

reg missing pciICindex_1 if taxid==1, cluster(provinceID_2017)
outreg2 using "$result/Table20.xls", label excel nocons addtext(Sample, border tax survey& taxid=1) addnote("Standard error cluster at the province level")
restore


**----------------------------------------------------------------------------**
**---Table 21: Interaction Effects of Corruption on Tax Compliance Ratio
**----------------------------------------------------------------------------**
global X_ctrls= "age sex i.educ i.location"
global C_GIS_ctrls = "area_km2 boundary_km lat lon"
global C_geo=" elev river suit_rice suit_tea suit_coffee suit_coconut suit_sugar slope tem precip"
global C_policy_ctrls = "ezone_c izone_c taxreduc"
global econ_formal= "nfirmf ld_endme ld_endm ts_asset_endme ts_asset_endm kqkd_rev_busme kqkd_rev_busm kqkd_prof_bftaxme kqkd_prof_bftaxm"
global C_governance="pciECindex_1 pciLAindex_1 pciTindex_1 pciTCindex_1  pciBindex_1 pciPindex_1 pciBSSindex_1 pciLTindex_1 pciLIindex_1"

foreach i in  notraining rest man male house{
	g corrupt_`i'= pciICindex_1*`i'
}
	
g corrupt_worker_99= pciICindex*worker_total_99
*g corrupt_operation_hr= pciICindex* operation_hr
	
label var worker_total_99 "#workers"
label var operation_hr "Operating Hours"
label var corrupt_worker_99 "Corrupt&Workers"
label var corrupt_operation_hr "Corrupt&Operation Hours"
label var corrupt_rest "corrupt& restaurant"
label var corrupt_man "corrupt& manufacturing"
label var corrupt_male "corrupt& male"
label var corrupt_house "corrupt& operate in owner's house"
label var corrupt_notraining "corrupt& owner no no training"

preserve
keep if thue11_r99<.& taxid==1
	
reghdfe thue11_r99 pciICindex_1 worker_total_99 corrupt_worker_99 $C_governance $X_ctrls $C_policy_ctrls $C_GIS_ctrls  light16_mean $C_geo $econ_formal if thudn1>100000& thudn1<.& econ_formal==1 ///
	  , absorb(com_pairID ind3) cluster(provinceID_2017 borderID )
	  
outreg2 using  "$result/Table21.xls", replace label excel keep(corrupt_*) ///
nocons addtext(Sample, kmA0, borderID FE, Yes, 3digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Light2016, Yes, ///
			   Only no-missing geo controls, Yes, Geo controls, Yes, Only no-missing formal sector activities, Yes, Formal sector activities Controls, Yes) ///
			   addnote("Control variables are the same as control variables in column (5) Table 4.  Two-way standard errors are clustered at the provincial and provincial border levels")
			   
					   
foreach i in rest man male notraining house {
	reghdfe thue11_r99 pciICindex_1 corrupt_`i' $C_governance $X_ctrls $C_policy_ctrls $C_GIS_ctrls  light16_mean $C_geo $econ_formal  if thudn1>100000& thudn1<.& econ_formal==1 ///
			  , absorb(com_pairID ind3) cluster(provinceID_2017 borderID )
			  
	outreg2 using  "$result/Table21.xls", label excel keep(corrupt_*) ///
	nocons addtext(Sample, kmA0, borderID FE, Yes, 3digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Light2016, Yes, ///
					   Only no-missing geo controls, Yes, Geo controls, Yes, Only no-missing formal sector activities, Yes, Formal sector activities Controls, Yes) ///
					   addnote("Control variables are the same as control variables in column (5) Table 4.  Two-way standard errors are clustered at the provincial and provincial border levels")
}	
restore	
	
	
**----------------------------------------------------------------------------**
**---Table 22: Testing grease the wheel hypothesis
**----------------------------------------------------------------------------**
g pciICindex_1s= pciICindex_1^2 

label var pciICindex_1 "Corruption"
label var pciICindex_1s "Corruption squared"

reghdfe taxid  pciICindex_1 pciICindex_1s if thudn1>100000& thudn1<.& econ_formal==1, absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
outreg2 using "$result/Table22.xls", replace label excel keep(pciIC*) nocons addtext(borderID FE, Yes, 3digit Industry FE)


reghdfe taxid  pciICindex_1 pciICindex_1s $depV_c  $X_ctrls $C_policy_ctrls $C_GIS_ctrls $C_geo $econ_formal light16_mean if thudn1>100000& thudn1<.& econ_formal==1, absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
outreg2 using "$result/Table22.xls", label excel keep(pciIC*) nocons addtext(borderID FE, Yes, 3digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, ///
	    Commune's policy controls, Yes, Commune's GIS controls, Yes, Light2016, Yes, Only no-missing geo controls, Yes, Geo controls, Yes, Only no-missing formal sector activities, Yes, Formal sector activities Controls, Yes)  
		  
		  